package com.zzyl.nursing.dto;

import com.zzyl.common.utils.StringUtils;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

@Data
@Slf4j
public class HandleAlertDataDTO {
    @NotNull(message = "报警数据ID不能为空")
    private Long id;
    
    @NotBlank(message = "处理结果不能为空")
    private String processingResult;

    private String processingTime;

    public LocalDateTime getProcessingTime() {
        if (StringUtils.isBlank(processingTime)) {
            return LocalDateTime.now();
        }
        try {
            // 尝试解析ISO格式
            if (processingTime.contains("T") && processingTime.contains("Z")) {
                return Instant.parse(processingTime)
                        .atZone(ZoneId.systemDefault())
                        .toLocalDateTime();
            }

            // 尝试解析普通格式
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
            return LocalDateTime.parse(processingTime, formatter);

        } catch (Exception e) {
            log.warn("处理时间格式解析失败: {}, 使用当前时间", processingTime);
            return LocalDateTime.now();
        }
    }
}